<?
/**
 * VoiceOne Settings/Tool/macro/edit
 *
 * Frontend to provide access to the tech system in voiceone.
 * @package voiceone
 * @subpackage  settings_tool
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage; 
  
  
  //================ PAGE LOGIC ================
  if (count($_POST)>0) {

    //errArr($_POST["code"]);
  
    $entry=Array(
      "id" => $_POST["id"],
      "name" => $_POST["name"],
      "label" => $_POST["label"],
      "description" => $_POST["description"], 
      "parameter" => $_POST["parameter"], 
      "code" => $_POST["code"]  
    ); 
    
    //save the group informations
    $ret=$asterisk->putMacro($entry);
    if ($ret>0) $alert="<div class=\"AlertGood\">".T_("The macro has been saved")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The macro has been saved")."</div>";
    goToMainPage($alert);
  }
  //--------------------------------------------------------------------------
  
  $pageTitle="New Macro";
  $ret=$asterisk->getMacro(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  if (is_array($ret)) 
  foreach($ret as $m) {
    $macroList.="<li><a href=\".?id=".$m["id"]."\">".$m["label"]."</a></li>";

    //if modify, read the group informations
    if (isset($_GET["id"]) and $m["id"]==$_GET["id"]) {
      $id=$m["id"];
      $name=$m["name"];
      $label=$m["label"];
      $description=$m["description"];
      $parameter=$m["parameter"];
      $code=$m["code"];
      $pageTitle="Edit macro $label";
    }  
  }

  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="macro";include("../../navigation.php");?>
  
  <div class="SectionHeader">
    <h1><?=$pageTitle?></h1>
    <h3><a href="../" class="admin" ><?=T_("Return without save")?></a></h3>
  </div>

  <div id="basic_form">
    <form action="<?=$PHP_SELF?>" method="post">
      <p class="blockintro"><?=T_("Edit your the settings of this macro")?></p>
      <div class="block">
        <dl>
          <dt class="required"><?=T_("Name")?>:</dt>
          <dd><input type="textfield" id="name" name="name" value="<?=$name?>" /></dd>
          <dt class="required"><?=T_("Label")?>:</dt>
          <dd><input type="textfield" id="label" name="label" value="<?=$label?>" /></dd>
          <dt class="required"><?=T_("Description")?>:</dt>
          <dd><textarea id="description" name="description" style="width: 500px"><?=$description?></textarea></dd>
          <dt class="required"><?=T_("Parameter")?>:</dt>
          <dd><textarea id="parameter" name="parameter"  wrap="off" style="width: 500px; height: 100px"><?=$parameter?></textarea></dd>
          <dt class="required"><?=T_("Code")?>:</dt>
          <dd><textarea id="code" name="code" wrap="off" style="width: 500px; height: 150px"><?=$code?></textarea></dd>
        </dl>
        <div class="help">
          <br/>
          <?=T_("Note: in parameters, you can specify what input variable can accept this macro.<br/>Use this syntax:")?>
          <?=T_("<blockquote>&lt;param name=\"XXX\" type=\"YYY\" label=\"ZZZ\" description=\"KKK\" /&gt;</blockquote>
          where<br/><strong>name</strong> is the name of parameter,  <br/>
          <strong>label</strong> is the label of parameter, <br/>
          <strong>description</strong> is the text description of parameter, <br/>
          <strong>type</strong> is one of these values: QUEUE, GROUP, EXTENSION, 
          IVR, TEXTFIELD, EMAIL_EXTENSION, OUTGOING_RULE, INCOMING_RULE, SOUNDFILE, TRUNK, CONFERENCE <br/>
          Look at this example:
          
            <blockquote>&lt;param name=\"dest\" type=\"IVR\" label=\"Play this IVR\" description=\"bla bla\" /&gt;</blockquote>")?>
            
        </div>
        <input type="hidden" name="id" value="<?=$id?>" />
      </div>
      <div class="action">
        <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" />
      </div>
    </form>
  </div>      
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=T_("Macro List")?></h1>
          <p><?=T_("Choose the macro you want to edit")?>
            <ul>
              <?=$macroList?>
            </ul>
          </p>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

  $smarty->assign("section", "application");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

